﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace PhoneBilling.Controllers
{
    public static class Helper
    {
        public static string From10To16(int val10)
        {
            int low;
            int high =Math.DivRem(val10, 16, out low);
            return From10To16S(high) + From10To16S(low);
        }

        public static string From10To16S(int val10)
        {
            switch(val10)
            {
                case 0:
                    return "0";
                case 1:
                    return "1";
                case 2:
                    return "2";
                case 3:
                    return "3";
                case 4:
                    return "4";
                case 5:
                    return "5";
                case 6:
                    return "6";
                case 7:
                    return "7";
                case 8:
                    return "8";
                case 9:
                    return "9";
                case 10:
                    return "A";
                case 11:
                    return "B";
                case 12:
                    return "C";
                case 13:
                    return "D";
                case 14:
                    return "E";
                case 15:
                    return "F";
                default:
                    return "";

            }
        }

        public static int From16To10(string val10)
        {
            string high = val10[1].ToString();
            string low = val10[0].ToString();
            int vHigh = From16To10C(high);
            int vLow = From16To10C(low);

            return vHigh * 16 + vLow;
        }

        public static int From16To10C(string val10)
        {
            switch (val10)
            {
                case "0":
                case "1":
                case "2":
                case "3":
                case "4":
                case "5":
                case "6":
                case "7":
                case "8":
                case "9":
                    return Convert.ToInt32(val10);
                case "A":
                    return 10;
                case "B":
                    return 11;
                case "C":
                    return 12;
                case "D":
                    return 13;
                case "E":
                    return 14;
                case "F":
                    return 15;
                default:
                    return 0;

            }
        }
    }
}